#include "visualdata.h"
#include <QGraphicsLineItem>
#include <QApplication>

VisualData::VisualData()
{

}

void VisualData::Init(int dataCount)
{
    clear();
    _data.clear();
    _data.reserve(dataCount);

    _lines.clear();
    _lines.reserve(dataCount);

    for(int i = 0; i < dataCount; ++i){
        QGraphicsLineItem *pItem = addLine(i*4, 0, i*4, 400,
                                           QPen(Qt::red));
        _lines.push_back(pItem);
        _data.push_back(qrand()%600);
    }

    Refresh();
}

void VisualData::Refresh()
{
    for(int i = 0; i < _data.size(); ++i){
        QGraphicsLineItem *pItem = _lines[i];
        int data = _data[i];
        QLineF line = pItem->line();
        line.setP2(QPointF(line.p2().x(), -data));
        pItem->setLine(line);
    }
    qApp->processEvents();
}
